//房源panal
Ext.define('customer.payDeposit.view.estatePanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		var me=this;
		var row_1={
				xtype: "container",
	            layout: "hbox",
	            items:{
	            	xtype: 'displayfield',
	                fieldLabel: '无房认筹',
	                name:"paydepositName"
	            }
				
	    };
		var row_2={
				id:"isPaydepositTrue",
				fieldDefaults: {
			            labelAlign: 'top',
			            msgTarget: 'side'
			    },
			    defaults: {
			            border: false,
			            xtype: 'panel',
			            flex: 1,
			            layout: 'anchor'
			    },
			    border: false,
				layout: 'hbox',
				items: [{
		            items: [{
		            	xtype:'container',
		            	layout:'hbox',
		            	border:true,
		            	items:[{
		            		xtype:'displayfield',
			                fieldLabel: '房号',
			                name: 'combinedName'
			                }]
		                
		            }, {
		                xtype:'displayfield',
		                fieldLabel: '建筑面积(㎡)',
		                anchor: '80%',
		                name: 'buildingArea'
		            }, {
		                xtype:'displayfield',
		                fieldLabel: '分摊面积(㎡)',
		                anchor: '80%',
		                name: 'sharingArea'
		            }, {
		                xtype:'displayfield',
		                fieldLabel: '折前单价(元)',
		                anchor: '80%',
		                name: 'unitPrice',
		                readOnly:true
		            }]
		        }, {
		            items: [{
		                xtype:'displayfield',
		                fieldLabel: '房源状态',
		                anchor: '80%',
		                name: 'roomStatusName'
		            },{
		                xtype:'displayfield',
		                fieldLabel: '套内面积(㎡)',
		                anchor: '80%',
		                name: 'innerArea'
		            },{
		                xtype:'displayfield',
		                fieldLabel: '计价面积(㎡)',
		                anchor: '80%',
		                name: 'calculateArea'
		            },{
		                xtype:'displayfield',
		                fieldLabel: '折前总价(元)',
		                anchor: '80%',
		                name: 'totalPrice'
		            }]
		        }]
	    };
		var items=[row_1,row_2];
		var initConfigg = {
				id:'estatePanel',
				title:"房产信息",
				bodyStyle: 'padding:5px 5px 0',
		        minHeight: 200,
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5
		        },
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});


function vaildResult(url){
	   Ext.Ajax.request({
   	    url: contextPath+'/marketing/room/vaildNeedReceive',
   	    params: {
   	    	payId: payDepositeId
   	    },
   	    method: 'POST',
   	    success: function(response){
   	        var text = Ext.decode(response.responseText);
   	        if(text.result=="1"){
   	        	Ext.Msg.alert('提示', text.msg);
   	        }else if(text.result=="0"){
   	        	window.location.href=url;
   	        }
   	    }
   	});
}

Ext.define('customer.payDeposit.view.customerPanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		var me=this;
		var row_1={
				fieldDefaults: {
			            labelAlign: 'top',
			            msgTarget: 'side'
			    },
			    border: false,
			    defaults: {
			            border: false,
			            xtype: 'panel',
			            flex: 1,
			            layout: 'anchor'
			    },
				layout: 'hbox',
				items: [{
		            items: [{
		            	xtype:'container',
		            	layout:'hbox',
		            	anchor: '80%',
		            	items:[{
		            		xtype:'displayfield',
			                fieldLabel: '客户姓名',
			                anchor: '80%',
			                name: 'customerName'
			                }]
		                
		            }, {
		                xtype:'displayfield',
		                fieldLabel: '证件类型',
		                anchor: '80%',
		                name: 'peDocumentTypeName'
		            }, {
		                xtype:'displayfield',
		                fieldLabel: '证件号码',
		                anchor: '80%',
		                name: 'peDocumentNumber'
		            }, {
		                xtype:'displayfield',
		                fieldLabel: '联系电话',
		                anchor: '80%',
		                name: 'customerPhone'
		            }]
		        }, {
		            items: [{
		                xtype:'displayfield',
		                fieldLabel: '邮寄地址',
		                anchor: '80%',
		                name: 'peContactAddress'
		            },{
		                xtype:'displayfield',
		                fieldLabel: '邮编',
		                anchor: '80%',
		                name: 'pePostcode'
		            },{
		                xtype:'displayfield',
		                fieldLabel: '客户来源',
		                anchor: '80%',
		                name: 'customerOriginName'
		            }]
		        }]
	    };

	
		var columns = [{
			text : "姓名",
			dataIndex : 'memberName',
			width:'25%'
		}, {
			text : "证件类型",
			dataIndex : 'documentType',
			width:'25%',
            renderer: function(value,metadata,record){  
                var index = documentTypeStore.find('value',value);  
                if(index!=-1){  
                    return documentTypeStore.getAt(index).data.name;  
                }  
                return value;  
            }
		},{
			text : "证件号码",
			dataIndex : 'documentNumber',
			width:'25%'
		},{
			text : "手机号码",
			dataIndex : 'mobile',
			width:'20%'
		}];
		var row_2=Ext.create('Ext.grid.Panel', {
			id:'familyMemberGridPanel',
			region : 'south',
			title:"共同购房者",
			minHeight:200,
			columnLines: true,
	        viewConfig: {
	            stripeRows: true
	        },
			store : gridStore,
			columns : columns
		});
		var items=[row_1,row_2];
		var initConfigg = {
				id:'customerPanel',
		        title:"客户信息",
		        minHeight:320,
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5
		        },
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});
Ext.define('customer.payDeposit.view.payDepositPanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		var row_1={
				fieldDefaults: {
			            labelAlign: 'left',
			            msgTarget: 'side'
			    },
			    border: false,
			    defaults: {
			            border: false,
			            xtype: 'panel',
			            flex: 1,
			            layout: 'anchor'
			    },
				layout: 'hbox',
				items: [{
		            items: [{
		                xtype:'displayfield',
		                fieldLabel: '认筹编号',
		                anchor: '80%',
		                name: 'depositCode'
		            }
//		            , {
//		            	xtype:'container',
//		            	layout:'hbox',
//		            	anchor: '80%',
//		            	items:[{
//		            		xtype:'displayfield',
//			                fieldLabel:'有效日期',
//			                name:'startTime',
//			                renderer:function(val){
//			                	if(val==null||val==""){
//			                		return "";
//			                	}
//			                	return Ext.Date.format(new Date(val),'Y-m-d');
//			                }
//		            	},{
//		            		xtype:'displayfield',
//		            		hideLabel:true,
//		            		name:'endTime',
//			                renderer:function(val){
//			                	if(val==null||val==""){
//			                		return "";
//			                	}
//			                	return Ext.Date.format(new Date(val),'Y-m-d');
//			                }
//		            	}]
//		                
//		            }
		            , {
		                xtype:'displayfield',
		                fieldLabel: '经纪人',
		                anchor: '80%',
//		                name:'agentId',
		                value:userName
		            }, {
		                xtype:'displayfield',
		                fieldLabel: '业务状态',
		                anchor: '80%',
		                name:'businessStatus',
		                renderer : function(val) {
		                    if (val == 1) {
		                        return '认筹';
		                    } else if (val == 2) {
		                        return '认筹转认购';
		                    }else if (val == 3) {
		                        return '认筹转签约';
		                    }else if (val == 4) {
		                        return '已更名';
		                    }else if (val == 5) {
		                        return '退认筹';
		                    }
		                    return val;
		                }
		            },{
		            	xtype: 'displayfield',
		                fieldLabel: '备注',
		                anchor: '80%',
		                name:'remark'
		            }]
		        }, {
		            items: [{
		                xtype:'displayfield',
		                fieldLabel: '认筹金(元)',
		                anchor: '80%',
		                name: 'payDepositAmount'
		            },{
		                xtype:'displayfield',
		                fieldLabel: '已收认筹金(元)',
		                anchor: '80%',
		                name: 'payAepositAmount'
		            },{
		                xtype:'displayfield',
		                fieldLabel: '认筹日期',
		                anchor: '80%',
		                name:'didTime',
		                renderer:function(val){
		                	if(val==null||val==""){
		                		return "";
		                	}
		                	return Ext.Date.format(new Date(val),'Y-m-d');
		                }
		            }]
		        }]
	    };
		var items=[row_1];
		var initConfigg = {
				id:'payDepositPanel',
		        title:"认筹信息",
		        minHeight:200,
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5
		        },
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});

Ext.define('customer.payDeposit.viewPanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		var estatePanel= Ext.create("customer.payDeposit.view.estatePanel");
		var customerPanel= Ext.create("customer.payDeposit.view.customerPanel");
		var payDepositPanel= Ext.create("customer.payDeposit.view.payDepositPanel");
		//审批历史
		 var selectWindow=Ext.create('component.proces.history',{
			 processInstanceId: procInstId,
			 contextPath:contextPath
		 });
		//未提交状态，无审核记录，不显示
		 console.log("auditStatus = " + auditStatus);
		if("0" == auditStatus){
			selectWindow = null;
		}
		 
		 var fileAttachment = Ext.create('component.file.attachment',{
			    objectId: payDepositeId,
			    imageType: "7",
			    contextPath:contextPath
		 });
		var submitFun=function(){
       	   Ext.Ajax.request({
        	    url: contextPath+'/customer/payDeposit/add',
        	    params: {
        	    	payDepositeId: payDepositeId,
        	    	processKey:"cusPayDeposit"
        	    },
        	    method: 'POST',
        	    success: function(response){
        	        var text = Ext.decode(response.responseText);
        	        if(text.res=="1"){
        	        	Ext.Msg.alert('提示', '认筹成功！');
        	        }else if(text.res=="100"){
        	        	Ext.Msg.alert('提示', '权限不足！');
        	        }else{
        	        	Ext.Msg.alert('提示', '认筹失败！');
        	        }
        	    }
        	});
		};
		var defaultConfigg = {
				buttonAlign:'center',
				defaults: {  
		            split: true,    //有分割线  
		            collapsible: true  //可以折叠
		        },
		        renderTo:Ext.getBody(),
				items:[estatePanel,customerPanel,payDepositPanel,selectWindow,fileAttachment],
				tbar:[{hidden:marketingPayDepositReceivables,xtype: "button", text: "收款",iconCls:'icon-accept',
					    handler:function(){
					      var url=contextPath+'/marketing/proceeds/deposit?id='+payDepositeId;
			    	      window.location.href=url;
				        }
				},{hidden:marketingSubscribeAdd, xtype: "button", text: "认购",iconCls:'icon-accept', id:"renGou",
					     handler:function(){
					    	var baseUrl = returnUrl.replace("/", ",").replace("?", "(").replace("=", ")");
					    	while(baseUrl.indexOf('/') >= 0)
					    		baseUrl = baseUrl.replace("/", ",");
					    	while(baseUrl.indexOf('?') >= 0)
					    		baseUrl = baseUrl.replace("?", "(");
					    	while(baseUrl.indexOf('=') >= 0)
					    		baseUrl = baseUrl.replace("=", ")");
							var url=contextPath+'/customer/subscribe/toAdd?projectId='+projectId+'&payDepositId='+payDepositeId+'&returnUrl='+baseUrl;
							//验证数据
							vaildResult(url);
					    	
						}
				 },{hidden:marketingSignedAdd,xtype: "button", text: "签约",iconCls:'icon-accept', id:"qianYue",
					     handler:function(){
						    var baseUrl = returnUrl.replace("/", ",").replace("?", "(").replace("=", ")");
					    	while(baseUrl.indexOf('/') >= 0)
					    		baseUrl = baseUrl.replace("/", ",");
					    	while(baseUrl.indexOf('?') >= 0)
					    		baseUrl = baseUrl.replace("?", "(");
					    	while(baseUrl.indexOf('=') >= 0)
					    		baseUrl = baseUrl.replace("=", ")");
							var url=contextPath+'/customer/signed/toAdd?projectId='+projectId+'&payDepositId='+payDepositeId+'&returnUrl='+baseUrl;
							//验证数据
							vaildResult(url);
						 }
				 },{hidden:marketingPayDepositRetreat,xtype: "button", text: "解除认筹",iconCls:'icon-delete',
				         handler:function(){
							var url=contextPath+'/customer/payDeposit/toRetreat?payDepositId='+payDepositeId;
					    	window.location.href=url;
						 }
				 },{hidden:marketingPayDepositRetreatDtail,xtype: "button", text: "解除认筹详情",iconCls:'icon-delete',
			         handler:function(){
							var url=contextPath+'/customer/payDeposit/toRetreatView?id='+businessAbnormaId;
					    	window.location.href=url;
						 }
				 },{hidden:marketingPayDepositShou,id:'haveReceiveBtn',xtype: "button", text: "收款明细",iconCls:'icon-accept',
			         	 handler:function(){
							var url=contextPath+'/marketing/pin/haveReceive?receivablesType=0&relationId='+payDepositeId+"&returnBackParam="+returnBackParam;
					    	window.location.href=url;
						 }
				 }/*,{hidden:marketingPayDepositChangeName,xtype: "button", text: "更名",iconCls:'icon-user',handler:function(){
					 	
        		 	    location.href = contextPath + "/customer/payDeposit/toChangeName?payDepositId=" + payDepositeId;
					 
//					  var selectWindow=Ext.create('component.payDeposit.window',{
//						  payDepositId:payDepositeId
//					  });
//					  selectWindow.show();
					 
					 
				 }}*/]
		};
		Ext.apply(this,defaultConfigg);
		this.callParent(arguments);
	},
	buttons:[
	         {id:"retrunBtn",xtype: "button",text: "返回",handler: function(){
	        	 location.href=contextPath+returnUrl;
//	        	 history.go(-1);
	         }}
	]
});


